package com.ruoyi.parkingcar.service.impl;

import com.ruoyi.parkingcar.domain.ParkWallet;
import com.ruoyi.parkingcar.mapper.ParkWalletMapper;
import com.ruoyi.parkingcar.service.ParkWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ParkWalletServiceImpl implements ParkWalletService {


    @Autowired
    private ParkWalletMapper parkWalletMapper;

    //查询充值记录
    @Override
    public ParkWallet select(ParkWallet parkWallet) {
        return parkWalletMapper.selectParkWallet(parkWallet);
    }


    //实现计算金额
    @Override
    public void countMoney(ParkWallet parkWallet) {
        //拿到传入的订单金额
        double money = parkWallet.getMoney();

        //查找用户的余额

        ParkWallet parkWallet1 = parkWalletMapper.selectParkWallet(parkWallet);
        double money2 = parkWallet1.getMoney();
        //扣费
        double moneyIn = money2 - money;//拿到剩下的钱，更新钱包
        //修改钱包
        long customerId = parkWallet1.getCustomerId();
        parkWalletMapper.updateMoney(moneyIn,customerId);
    }
}
